package com.ruoyi.web.controller.emergencyplan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.emergencyplan.domain.MaterialItems;
import com.ruoyi.emergencyplan.service.IMaterialItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物料条目Controller
 * 
 * @author hcc
 * @date 2023-12-16
 */
@RestController
@RequestMapping("/emergencyplan/items")
public class MaterialItemsController extends BaseController
{
    @Autowired
    private IMaterialItemsService materialItemsService;

    /**
     * 查询物料条目列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialItems materialItems)
    {
        startPage();
        List<MaterialItems> list = materialItemsService.selectMaterialItemsList(materialItems);
        return getDataTable(list);
    }

    /**
     * 导出物料条目列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:export')")
    @Log(title = "物料条目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialItems materialItems)
    {
        List<MaterialItems> list = materialItemsService.selectMaterialItemsList(materialItems);
        ExcelUtil<MaterialItems> util = new ExcelUtil<MaterialItems>(MaterialItems.class);
        util.exportExcel(response, list, "物料条目数据");
    }

    /**
     * 获取物料条目详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(materialItemsService.selectMaterialItemsById(id));
    }

    /**
     * 新增物料条目
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:add')")
    @Log(title = "物料条目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialItems materialItems)
    {
        materialItems.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(materialItemsService.insertMaterialItems(materialItems));
    }

    /**
     * 修改物料条目
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:edit')")
    @Log(title = "物料条目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialItems materialItems)
    {
        return toAjax(materialItemsService.updateMaterialItems(materialItems));
    }

    /**
     * 删除物料条目
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:items:remove')")
    @Log(title = "物料条目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(materialItemsService.deleteMaterialItemsByIds(ids));
    }
}
